Learn how to implement search that can handle multiple languages.
Algolia’s search engine supports all writing systems and many languages, including symbol-based languages such as Chinese and Japanese. Algolia also handles multiple languages on the same website/app, meaning some users could search in French and some in English, using the same Algolia account.The purpose of this guide is to explain how to organize your indices to enable multi-language search.
Using one or multiple indices to handle multi-language search
Depending on your use case, you can use either one index for each language or one for all languages. The following questions can help you decide which approach is best for your use case:
You need a custom ranking per language/country. For example, you want to sort by price, and there are different pricing structures in different countries.
You want to support querying in multiple languages. For example, an Arabic-speaking user might use Arabic text for some words and the Roman alphabet for brand names.
Before deciding on this approach, find out if all the text you require from your list of supported languages will exceed
Algolia’s record size limits. If they do exceed the limit, use one index per language.
In this solution, you create one index for all languages. Your records contain text for each language and look like this:
json
Copy
Ask AI
[ { "objectID": 1, "title_eng": "The Wolf of Wall Street", "title_fr": "Le Loup de Wall Street", "title_es": "El lobo de Wall Street" }]
You now need to set the searchable attributes for all languages using searchableAttributes.
Copy
Ask AI
IndexSettings settings = new IndexSettings{ SearchableAttributes = new List<string> { "title_eng", "title_fr", "title_es" }};
Then at query time you must specify which attributes you want to be searchable, depending on the user’s language. Here’s how to do this with the JavaScript API client:
js
Copy
Ask AI
// search only in the French titlesindex .search("wolf", { restrictSearchableAttributes: "title_fr", }) .then(({ hits }) => { console.log(hits); });